package com.cloud.example.business.transaction.depend.worker;



import com.cloud.async.flow.callback.ICallback;
import com.cloud.async.flow.callback.IWorker;
import com.cloud.async.flow.worker.WorkResult;
import com.cloud.async.flow.wrapper.WorkerWrapper;
import com.cloud.example.business.mapper.CloudLogicMapper;
import com.cloud.example.business.mapper.entity.CloudLogicEntity;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author chengr
 */
@Component
public class DeWorker1 implements IWorker<WorkResult<User>, User>, ICallback<WorkResult<User>, User> {

    /**
     * logger
     */
    private final Log logger = LogFactory.getLog(getClass());

    @Autowired
    CloudLogicMapper cloudLogicMapper;

    @Override
    public User action(WorkResult<User> result, Map<String, WorkerWrapper> allWrappers) {
        logger.info("worker1 入参:" + result.getResult());

        CloudLogicEntity obj = new CloudLogicEntity();
        obj.setCustId(1L);
        obj.setLogicName("test");
        obj.setLogicContext("conteny");
        obj.setSubjectId(1L);
        cloudLogicMapper.save(obj);

        return new User("user1");
    }


    @Override
    public User defaultValue() {
        return new User("default User");
    }

    @Override
    public void begin() {

    }

    @Override
    public void result(boolean success, WorkResult<User> param, WorkResult<User> workResult) {
        logger.info("worker1 的结果是：" + workResult.getResult());
    }

}
